/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action;

import controller.Action;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Conta;
import model.Operacao;
import observer.BancoConcreto;
import persistense.ContaDAO;
import strategy.OperacaoSaldo;

/**
 *
 * @author Aurelio
 */
public class SaldoAction implements Action{
    private static final String HOME = "caixa.jsp";
    
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws IOException {           
        try {
            Operacao op = new OperacaoSaldo();
            String numeroConta = request.getParameter("numero_conta");
            Conta conta = ContaDAO.getInstance().recuperarContaporNumero(numeroConta);
            BancoConcreto bc = new BancoConcreto(conta, op);
            String resultadoObservador[] = bc.atualizar();
            request.setAttribute("corCampoSaldo",resultadoObservador[0]);
            request.setAttribute("mensagem", resultadoObservador[1]);
            request.setAttribute("saldo", op.recuperaSaldo(numeroConta));
            RequestDispatcher rd = request.getRequestDispatcher(HOME);
            rd.forward(request, response);
            
        } catch (ServletException ex) {
            Logger.getLogger(SaldoAction.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
  
}
